//
//  GongLueDetailViewController.m
//  MyProject
//
//  Created by apple on 15/11/2.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "GongLueDetailViewController.h"
#import "ChildrenModel.h"
#import "SectionsModel.h"
#import "LZXHelper.h"
@interface GongLueDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray  *_dataArr;
}
@end

@implementation GongLueDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   self.view.backgroundColor = [UIColor blackColor];
    [self getData];
    
    [self createView];
    
    [self createNavigationBar:9];
    [self.buttonA setImage:[UIImage imageNamed:@"collection-Small"] forState:UIControlStateNormal];
    self.back.text = @"攻略";
    
}

-(void)createView
{
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:1];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerNib:[UINib nibWithNibName:@"GongLueDetailCell" bundle:nil] forCellReuseIdentifier:@"456"];
}

-(void)getData
{
    _dataArr = [[NSMutableArray alloc]initWithArray:self.childrenArr];
    [_tableView reloadData];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataArr.count;
}
//每组多少个
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ChildrenModel *model = [_dataArr objectAtIndex:section];
    NSArray *arr = model.sections;

    return arr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChildrenModel *model = [_dataArr objectAtIndex:indexPath.section];
    NSArray *arr = model.sections;
    SectionsModel * model1 = [arr objectAtIndex:indexPath.row];
    
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"456"];
    
    UILabel * lable = (UILabel *)[cell.contentView viewWithTag:1002];
    lable.text = model1.desc;
    
    //行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineSpacing = 5;
    NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:13], NSParagraphStyleAttributeName:paragraphStyle};
    lable.attributedText = [[NSAttributedString alloc]initWithString:lable.text attributes:attributes];

    
    UILabel * lable1 = (UILabel *)[cell.contentView viewWithTag:1000];
    lable1.text = model1.title;

    
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    ChildrenModel *model = [_dataArr objectAtIndex:section];
    UILabel * lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
    lable.textAlignment = 1;
    
    lable.text = model.title;
    
    
    return lable;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}

//每个cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ChildrenModel *model = [_dataArr objectAtIndex:indexPath.section];
    NSArray *arr = model.sections;
    SectionsModel * model1 = [arr objectAtIndex:indexPath.row];
    
    float height = [LZXHelper textHeightFromTextString:model1.desc width:[UIScreen mainScreen].bounds.size.width-20 fontSize:16];
    

    
    
    return height +40;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
